import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/scss/reset.scss'
import '@/assets/scss/style.scss'
import '@/assets/iconfont/iconfont.css'
//引入组件库
import ElementPlus from 'element-plus'
import locale from 'element-plus/lib/locale/lang/zh-cn'
import 'element-plus/dist/index.css'

import debouncePlugin from './utils/debounce'

const app= createApp(App)

// 在实例上绑定全局方法resetSetItem
app.config.globalProperties.$resetSetItem = function (key:string, newVal:any) {
    if (key === 'x') {
        // 创建一个StorageEvent事件
        const newStorageEvent = document.createEvent('StorageEvent');
        const storage = {
            // 对SetItem事件进行监听
            setItem: function (k:string, val:any) {
                sessionStorage.setItem(k, val);
                // 初始化创建的事件
                newStorageEvent['initStorageEvent']('setItem', false, false, k, null, val, undefined, null)
                // 派发对象
                window.dispatchEvent(newStorageEvent)
            }
        }
        return storage.setItem(key, newVal);
    }
 }
 app.use(store).use(router).use(ElementPlus,{locale}).use(debouncePlugin).mount('#app')
